<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 用户表的列表信息
 * @author chenhuan
 *
 */
class Userborrow extends CI_Controller {
	
	function __construct(){
		parent::__construct();
		/** 登陆验证 */
		$user = $this->session->userdata('ych_user');
		if(!isset($user['user_id'])){
			$str = $_SERVER['REQUEST_URI'];
			header('Location: /mobile/login/index/index.html');
		}elseif((time() - $user['login_time']) > 3600*2){
			header('Location: /mobile/login/index/index.html');
		}
	}
	
	/**
	 * 代收明细
	 */
	function coll(){
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		$user = $this->session->userdata('ych_user');
		$data['where']['user_id'] 	= $user['user_id'];
		$data['where']['fstatus'] 	= 0;
		$data['select'] 	= 1;
		$data['order'] 		= 1;
		$data['page_size']  = 8;
		$data['page_start'] = (int)$per_page;
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$coll['title'] 	= utf8substr($coll['title'], 0, 8);
			$coll['repay_time'] = date('m-d H:i', $coll['repay_time']);
			$coll['capital'] 	= number_format($coll['capital'], 2);
			$coll['interest'] 	= number_format($coll['interest'], 2);
			$collection_list[] = $coll;
		}
		$vdata['collection_list'] = $collection_list;
		$this->load->view('/mobile/user_collcetion_list', $vdata);
	}
	
	/**
	 * 代收明细
	 */
	function coll_more($page = 0){
		$per_page 			= intval($page);
		$user = $this->session->userdata('ych_user');
		$data['where']['user_id'] 	= $user['user_id'];
		$data['where']['fstatus'] 	= 0;
		$data['select'] 	= 1;
		$data['order'] 		= 1;
		$data['page_size']  = 8;
		$data['page_start'] = $per_page;
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$coll['title'] 	= utf8substr($coll['title'], 0, 8);
			$coll['repay_time'] = date('m-d H:i', $coll['repay_time']);
			$coll['capital'] 	= number_format($coll['capital'], 2);
			$coll['interest'] 	= number_format($coll['interest'], 2);
			$collection_list[] = $coll;
		}
		echo json_encode($collection_list);
	}
	
	
	/**
	 * 已收明细
	 */
	function ycoll(){
		$per_page 			= $this->input->get('per_page')?$this->input->get('per_page'):0;
		
		$user = $this->session->userdata('ych_user');
		$data['where']['user_id'] 	= $user['user_id'];
		$data['where']['fstatus'] 	= 1;
		$data['select'] 	= 1;
		$data['order'] 		= 4;
		$data['page_size']  = 8;
		$data['page_start'] = (int)$per_page;
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$coll['title'] 	= utf8substr($coll['title'], 0, 8);
			$coll['repay_yestime'] = date('m-d H:i', $coll['repay_yestime']);
			$coll['capital'] 	= number_format($coll['capital'], 2);
			$coll['interest'] 	= number_format($coll['interest'], 2);
			$collection_list[] = $coll;
		}
		$vdata['collection_list'] = $collection_list;
		$this->load->view('/mobile/user_ycollcetion_list', $vdata);
	}
	
	/**
	 * 代收明细
	 */
	function ycoll_more($page = 0){
		$per_page 			= intval($page);
		$user = $this->session->userdata('ych_user');
		$data['where']['user_id'] 	= $user['user_id'];
		$data['where']['fstatus'] 	= 1;
		$data['select'] 	= 1;
		$data['order'] 		= 4;
		$data['page_size']  = 8;
		$data['page_start'] = $per_page;
		$this->load->model('Borrow_model');
		$res_data = $this->Borrow_model->get_user_collection($data);
		$collection_list = array();
		foreach($res_data['collection_list'] as $coll){
			$coll['title'] 	= utf8substr($coll['title'], 0, 8);
			$coll['repay_yestime'] = date('m-d H:i', $coll['repay_yestime']);
			$coll['capital'] 	= number_format($coll['capital'], 2);
			$coll['interest'] 	= number_format($coll['interest'], 2);
			$collection_list[] = $coll;
		}
		echo json_encode($collection_list);
	}
	
}
